#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../include/video_manager.h"
#include "../include/config.h"
//#include <video_manager.h>
//#include <config.h>

static PT_VideoOpr g_ptVideoOprHead = NULL;

int RegisterVideoOpr(PT_VideoOpr ptVideoOpr)
{
    if(!g_ptVideoOprHead)
    {
        g_ptVideoOprHead = ptVideoOpr;
        ptVideoOpr->ptNext = NULL;
    }
    else
    {
        PT_VideoOpr ptTmp = g_ptVideoOprHead;
        while(ptTmp->ptNext)
        {
            ptTmp = ptTmp->ptNext;
        }
        ptTmp->ptNext = ptVideoOpr;
        ptVideoOpr->ptNext = NULL;
    }

    return 0;
}

int VideoDeviceInit(char *strDevName, PT_VideoDevice ptVideoDevice)   
{
    int ret;
    PT_VideoOpr ptTmp = g_ptVideoOprHead;

    while(ptTmp)
    {
        ret = ptTmp->InitDevice(strDevName, ptVideoDevice);
        if(ret == 0)    //如果初始化成功
            return 0;
        ptTmp = ptTmp->ptNext;   //否则判断下一个是否可用
    }

    return -1;
}


int VideoInit()
{
    int ret;

    ret = V4l2Init();  //这里的Init只是将V4l2VideoOpr注册到g_ptVideoOprHead为头的链表中

    return ret;
}

